<h2>HowBusy</h2>

<% if @how_busy.messages.size > 0 %>
<div>
	Notice
	<ul>
		<% for message in @how_busy.messages %>
		<li><%= message %></li>
		<% end %>
	</ul>
</div>
<% end %>


<div id="how_busy_form_block">
	<fieldset>
		<legend>検索条件</legend>
		<% form_for :how_busy, :url =>{:action => 'index'} do |f|  %>

			<%= hidden_field_tag 'project_id', params[:project_id] %>
			<p id="date-options">
				<%= radio_button_tag 'how_busy[period_type]', '1', @how_busy.period_type == 1 %>
				<label>Before：</label><br />
				<%=
					select_tag('how_busy[period_past]',
						options_for_select(
							['1', '2', '3', '5', '7', '10', '14', '30'],
							@how_busy.period_past.to_s),
						:onfocus => '$("how_busy_period_type_1").checked = true;')
				%>Days<br />
				<label>After：</label><br />
				<%=
					select_tag('how_busy[period_future]',
						options_for_select(
							['1', '2', '3', '5', '7', '10', '14', '30'],
							@how_busy.period_future.to_s),
						:onfocus => '$("how_busy_period_type_1").checked = true;')
				%>Days<br /><br />
			</p>
			<p id="date-options">
				<%= radio_button_tag 'how_busy[period_type]', '2', @how_busy.period_type == 2 %>
				<span onclick="$('how_busy_period_type_2').checked = true;">
					<label for="how_busy_period_from">From:</label><br />
					<%= f.text_field "period_from", :size => 10 %><%= calendar_for('how_busy_period_from') %><br />
					<label for="how_busy_period_to">To:</label><br />
					<%= f.text_field "period_to", :size => 10 %><%= calendar_for('how_busy_period_to') %><br />
				</span>
			</p>

<% if false %>
			<p>
				<label for="timesheet_sort"><%= l(:timesheet_group_by) %>:</label><br />
				<%= select_tag("timesheet[sort]", options_for_select(Timesheet::ValidSortOptions.invert, @timesheet.sort)) %>
			</p>
			<p>
				<label for="timesheet[projects][]"><%= l(:timesheet_project_label)%>:</label><br />
				<%= select_tag 'timesheet[projects][]',
					options_from_collection_for_select(@timesheet.allowed_projects, :id, :name, @timesheet.projects.collect(&:id)),
					{ :multiple => true, :size => @list_size}
				%>
			</p>
			<p>
				<label for="timesheet[users][]"><%= l(:timesheet_users_label)%>:</label><br />
				<%= select_tag 'timesheet[users][]',
					options_from_collection_for_select(User.find(:all, :conditions => ['status = ?', User::STATUS_ACTIVE]).sort { |a,b| a.to_s.downcase <=> b.to_s.downcase }, :id, :name, @timesheet.users),
					{ :multiple => true, :size => @list_size}
				%>
			</p>
<% end %>
			<div class="clear">
			</div>
			<%= submit_tag l(:button_apply),:class => 'button-small' -%>

		<% end %>
	</fieldset>
</div>



<% if @how_busy.status != HowBusy::StatusType[:error] %>
<% form_tag({}) do %>
	<div class="how_busy_main_block">
		<table class="how_busy_table" style="width:<%= (@how_busy.date_num + 1) * 100 %>px">
			<thead>
				<%=
					render :partial => 'how_busy/header.rhtml', :locals => {
						:date_from => @how_busy.date_from,
						:date_to => @how_busy.date_to
					}
				%>
			</thead>
			<tbody>
				<% @how_busy.project.users.each do |user| %>
				<%=
					render :partial => 'how_busy/row.rhtml', :locals => {
						:regular_work_hours => @how_busy.regular_work_hours,
						:date_from => @how_busy.date_from,
						:date_to => @how_busy.date_to,
						:user_name => user.name,
						:issues => @how_busy.issues_by_user[user.id],
						:entries => @how_busy.entries_by_user[user.id]
					}
				%>
				<% end %>
			</tbody>
		</table>
	</div>
<% end %>
<% end %>

<% content_for :header_tags do %>
    <%= javascript_include_tag 'context_menu' %>
    <%= stylesheet_link_tag 'context_menu' %>
<% end %>

<div id="context-menu" style="display: none;"></div>
<%= javascript_tag "new ContextMenu('#{url_for(:controller => 'issues', :action => 'context_menu')}')" %>

<% content_for :header_tags do %>
    <%= stylesheet_link_tag 'how_busy', :plugin => 'redmine_how_busy' %>
	<%= javascript_include_tag 'how_busy', :plugin => 'redmine_how_busy' %>
<% end %>
